<template>
	<view class="content">
		<view class="main">
			<view class="mainTop">
				<view class="jobName">
					<text>{{details.positionName}}</text>
          <view v-if="details&&details.salaryType===1">
            <text class="right" v-if="details&&details.positionSalary===5">【{{details&&details.positionSalaryValue}}】</text>
            <text class="right" v-else>
              【{{details.positionSalaryValue}}/月】
            </text>
            <text class="right">{{details.salaryMonth}}薪</text>
          </view>
          <view v-else><text class="right">【{{details.daySalaryValue }}/日】</text>
          </view>
				</view>
				<view class="about">
					<text v-for="(k,v) in positionTagsList" :key="v">{{k}}</text>
				</view>
				<view class="address">
					<text class="light">工作经验：</text>
					<text>{{details.txtExperience}}</text>
				</view>
				<view class="tel">
					<text class="light">学历：</text>
					<text>{{details.txtEducation}}</text>
				</view>
        <view class="address">
          <text class="light">福利待遇：</text>
           <view class="u-flex">
             <view v-for="(item,index) in positionWelfare" :key="index">
               <text>{{item}}</text>
             </view>
           </view>
        </view>
			</view>
			<view class="mainBottom">
				<view class="jobText">
					<text>工作描述</text>
				</view>
				<view class="describe">
					<text>
            <u-parse :html="details.positionDesc"></u-parse>
          </text>
				</view>
			</view>
      <view class="buttom" @click="onRouter">
        <button type="default">重新编辑</button>
      </view>
		</view>

		<Tabbar :current="3"></Tabbar>
	</view>
</template>

<script>

  import {comDeliveryInfo} from '@/api/myCompan'
  import { getDictItems } from '@/api/dict'
	export default {
		data() {
			return {
        positionId:null,//职位id
        details:{}//详情数据
			};
		},
    onLoad({id}){
      this.positionId = id
      this.comDeliveryInfo( id )
    },
    computed:{
      //福利
      positionWelfare(){
        const a=this.details?.positionWelfare
        return a&&a.split(',')
      },
      //标签
      positionTagsList(){
        const a=this.details?.positionTags??''
        if(!a.length){
          return []
        }
        const list = []
        if(a.includes(',')){
          a.split(',').map(item=>{
            list.push(item)
          })
        } else {
          list.push(a)
        }
        return list
      }
    },
		methods: {
      //进行编辑
      onRouter(){
        const index = this.details.recruitmentType
        const id=  this.positionId
        let url = ''
        const path = `/pages/publishUniversity/publishUniversity`
        if(index===3){
          url=`${path}?type=practice&index=3&id=${id}`
        } else if(index===2){
          url=`${path}?type=school&index=2&id=${id}`
        } else if(index===1){
          url=`${path}?type=practise&index=1&id=${id}`
        }
        this.$navigateTo(url)

      },
      //人数company_scale 1
      //公司类型company_type 2
      //学历user_education 4
      //月薪position_salary 6
      //日薪day_salary 7
      getDictItemsType(type=1,key='company_scale'){
        getDictItems(key).then(res=>{
          const {code,result,success} = res;
          if(success&&code===200){
            const details = this.details
            if(result.length){
              result.map(item=>{
                if(type===1){
                  if(details.companyScale===+item.value){
                    this.$set(details,'companyScaleValue',item.title)
                  }
                }else if(type===2){
                  if(details.companyType===+item.value){
                    this.$set(details,'companyTypeValue',item.title)
                  }
                }else if(type===3){
                  if(details.companySecondCategory===+item.value){
                    this.$set(details,'companySecondCategoryValue',item.title)
                  }
                } else if(type===4){
                  if(details.education===+item.value){
                    this.$set(details,'educationValue',item.title)
                  }
                } else if(type===5){
                  if(details.experience===+item.value){
                    this.$set(details,'experienceValue',item.title)
                  }
                }else if(type===6){
                  if(details.positionSalary===+item.value){
                    this.$set(details,'positionSalaryValue',item.title)
                  }
                }else if(type===7){
                  console.log ( details.daySalary,item.value,222 )
                  if(details.daySalary===+item.value){
                    this.$set(details,'daySalaryValue',item.title)
                  }
                }
              })
              this.$forceUpdate()
            }

          }
        }).catch(err=>{
          console.log (err)
        })
      },
      //详情
      comDeliveryInfo(id){
        comDeliveryInfo(id).then(res=>{
          const {code,result} = res
          if(code===200){
            this.details = result
            this.getDictItemsType(1,)
            this.getDictItemsType(2,'day_salary')
            this.getDictItemsType(3,'company_second_category')
            this.getDictItemsType(4,'user_education')
            this.getDictItemsType(5,'experience')
            this.getDictItemsType(6,'position_salary')
            this.getDictItemsType(7,'day_salary')
          }
        }).catch(e=>{
          console.log ( e )
        })
      },
			//跳转列表对应页面
			nextPage(url) {
				uni.navigateTo({
					url: url,
					fail() {
						uni.switchTab({
							url: url,
							fail() {
								uni.showToast({
									title: '暂未开通，敬请期待！',
									icon: 'none'
								});
							}
						});
					}
				});
			},
      //打电话
      onMakePhoneCall(phoneNumber){
        this.$onMakePhoneCall(phoneNumber)
      }
		}
	}
</script>

<style lang="scss" scoped>
.content{
	// background-repeat: no-repeat;
	// background-size: 100%;
	.header{
		background: linear-gradient(90deg, #52B8B2 0%, #5EC8A3 100%);
		.title{
			position: relative;
			width: 100%;
			height: 120rpx;
			line-height: 120rpx;
			text-align: center;
			.u-icon{
				position: absolute;
				height: 120rpx;
				left: 20rpx;
			}
			text{
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
			}
		}
	}
	.main{
		padding: 30rpx;
		height: 100vh;
		background: #F0F3F5;
		.mainTop{
			padding: 20rpx;
			background: #FFFFFF;
			border-radius: 10rpx;
			.jobName{
				margin: 10rpx 0;
				display: flex;
				justify-content: space-between;
				text{
					font-size: 32rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #323233;
				}
				.right{
					color: #53BAB0;
				}
			}
			.about{
				display: flex;
				justify-content: space-between;
				white-space: nowrap;
				flex-wrap: wrap;
				margin-top: 20rpx;
				text{
					flex-basis: 23%;
					margin-bottom: 10rpx;
					padding: 10rpx 0;
					text-align: center;
					font-size: 24rpx;
					background: #F3F3F3;
					border-radius: 4rpx;
				}
			}
			.light{
				color: #969799;
			}
			.address{
				margin: 10rpx 0;
				text{
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
				}
			}
			.tel{
				text{
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
				}
			}
		}
		.mainBottom{
			margin-top: 30rpx;
			padding: 20rpx;
			background: #FFFFFF;
			border-radius: 10rpx;
			.jobText{
				margin: 10rpx 0 20rpx 0;
				text{
					font-size: 32rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #323233;
				}
			}
			.describe{
				text{
					display: block;
					margin-bottom: 14rpx;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #646566;
				}
			}
		}
	}
}
.buttom{
  margin-top:100rpx;
}
.u-flex{
  flex-wrap: wrap;
  justify-content: start;
  view{
    width: 23%;
  }
}
</style>
